#include "swpactivityconnectorgraphicitem.h"

#include "graphicitemcommon.h"

#include <pathgraphicitem.h>

using namespace core;
using namespace swp;

SwpActivityConnectorGraphicItem::SwpActivityConnectorGraphicItem(
    QGraphicsItem* parent) : AbstractLineGraphicItem(
        QPointF(),
        QPointF(),
        QList<QPointF>(),
        parent)
{
    setFlags(flags() | QGraphicsItem::ItemIsSelectable);

    createArrows();

    updateLine();
}

SwpActivityConnectorGraphicItem::SwpActivityConnectorGraphicItem(
    const QPointF& startPoint,
    const QPointF& endPoint,
    const QList<QPointF>& anchors,
    QGraphicsItem* parent) : AbstractLineGraphicItem(
        startPoint,
        endPoint,
        anchors,
        parent)
{
    setFlags(flags() | QGraphicsItem::ItemIsSelectable);

    createArrows();

    updateLine();
}

SwpActivityConnectorGraphicItem::~SwpActivityConnectorGraphicItem()
{

}

int SwpActivityConnectorGraphicItem::type() const
{
    return SWP_ACTIVITY_CONNECTOR_ITEM;
}

QString SwpActivityConnectorGraphicItem::name() const
{
    return QObject::tr("Activity connector");
}

IEditorItem* SwpActivityConnectorGraphicItem::copy() const
{
    return new SwpActivityConnectorGraphicItem();
}

QList<Property> SwpActivityConnectorGraphicItem::properties() const
{
    QList<Property> ret;

    return ret;
}

QVariant SwpActivityConnectorGraphicItem::propertyValue(
    const QString& propertyName) const
{
    QVariant ret;

    return ret;
}

void SwpActivityConnectorGraphicItem::propertyChanged(const QString& property,
    const QVariant& newValue, bool silent)
{

}

QVariantList SwpActivityConnectorGraphicItem::optionList(
    const QString& propertyName) const
{
    QVariantList ret;

    return ret;
}

QVariantList SwpActivityConnectorGraphicItem::autocomplete(
    const QString& propertyName) const
{
    QVariantList ret;

    return ret;
}

QPair<QPen, QBrush> SwpActivityConnectorGraphicItem::endArrowPalette() const
{
    QPair<QPen, QBrush> ret;

    QPen pen(QColor(Qt::transparent));
    QBrush brush(QColor(Qt::black));

    ret.first = pen;
    ret.second = brush;

    return ret;
}

void SwpActivityConnectorGraphicItem::createArrows()
{
    QPainterPath _path(QPointF(-6, -6));

    _path.lineTo(6, 0);
    _path.lineTo(-6, 6);

    QPainterPathStroker stroker;
    stroker.setCapStyle(Qt::SquareCap);
    stroker.setJoinStyle(Qt::RoundJoin);
    stroker.setWidth(2);

    QPainterPath crop;
    crop.addRect(-6, -6, 12, 12);

    QPainterPath _endArrow = stroker.createStroke(_path);

    setEndArrow(new gui::PathGraphicItem(_endArrow.intersected(crop)));
}
